﻿using System.Collections.Generic;
using METU_CMT.Business.Compression;

namespace METU_CMT.Business
{
    public class Team
    {
        private int teamId;
        private List<Deliverable> deliverables;
        private List<Student> members;
        private string logoFile;
        private string teamName;

        public Team(string teamName)
        {
            this.teamName = teamName;
        }

        public int TeamId
        {
            get { return teamId; }
            set { teamId = value; }
        }

        public List<Deliverable> Deliverables
        {
            get { return deliverables; }
            set { deliverables = value; }
        }

        public List<Student> Members
        {
            get { return members; }
            set { members = value; }
        }

        public string LogoFile
        {
            get { return logoFile; }
            set { logoFile = value; }
        }

        public string TeamName
        {
            get { return teamName; }
            set { teamName = value; }
        }

        void SetTeamInfo(string logoFile, string teamName)
        {

        }

        public Team(int teamId)
        {
            TeamTableAdapter _teamTableAdapter = new TeamTableAdapter();
            deliverables = _teamTableAdapter.GetTeamDeliverables(teamId);
            this.teamId = teamId;
            members = _teamTableAdapter.GetMembers(teamId);
            logoFile = _teamTableAdapter.GetLogoFile(teamId);
            teamName = _teamTableAdapter.GetTeamName(teamId);
        }

        public void UploadDeliverable(Deliverable deliverable, int userid )
        {
            deliverables.Add(deliverable);
            TeamTableAdapter _teamTableAdapter = new TeamTableAdapter();
            _teamTableAdapter.UploadDeliverable(teamId, deliverable, userid);

        }

        public void DeleteMember(Student student)
        {
            members.RemoveAll( _student => _student.UserId == student.UserId );

            TeamTableAdapter _teamTableAdapter = new TeamTableAdapter();
            _teamTableAdapter.RemoveStudent(teamId, student);

        }

        public void DownloadDeliverable(Event @event)
        {
            deliverables.FindLast(deliverable => deliverable.Event.EventId == @event.EventId).Download();
        }

        //public void DownloadAllDeliverables()
        //{
        //    CompressionAdapter _compressionAdapter = new CompressionAdapter();
        //    foreach (var _deliverable in deliverables)
        //    {
        //        _compressionAdapter.AddFile(_deliverable, TODO );
        //    }
        //    _compressionAdapter.CompressAndDownloadDeliverables();
        //}
    }
}